package com.hichao.cs.base.controller;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import com.hichao.cs.helper.CSHelper;

public class BaseController implements CSHelper {
	
	protected  void DisplayHttpServletRequest(HttpServletRequest request) {

		logger.info("[Request] URL: {}", request.getRequestURL().toString());
		/*
		logger.info("[Request] URI: {}", request.getRequestURI().toString());
		logger.info("[Request] Query String: {}",  request.getQueryString());
		logger.info("[Request] Remote User: {}",  request.getRemoteUser());
		logger.info("[Request] Remote Address: {}",  request.getRemoteAddr());
		logger.info("[Request] Remote Host: {}",  request.getRemoteHost());
		logger.info("[Request] Remote Port: {}",  request.getRemotePort());
		logger.info("[Request] Local Address: {}", request.getLocalAddr());
 		logger.info("[Request] Local Name: {}", request.getLocalName());//blocked seconds
		logger.info("[Request] Method: {}", request.getMethod());//blocked seconds
		Cookie[] cookies = request.getCookies();
		if (cookies != null)
			for(int i = 0; i < cookies.length; i++)
				logger.info("[Request] Cookie: %s=%s", cookies[i].getName(), cookies[i].getValue());
		else
			logger.info("[Request] Cookies: There is no cookie.");
		*/
		Enumeration<?> hn = request.getHeaderNames();
		while(hn.hasMoreElements()){
			String name = (String)hn.nextElement();
			String value = request.getHeader(name);
			logger.info("[Request] Header: {}={}", name, value);
        }
		Enumeration<?> pn = request.getParameterNames();
		while(pn.hasMoreElements()){
			String name = (String)pn.nextElement();
			String value = request.getParameter(name);
			logger.info("[Request] Parameter: {}={}", name, value);
        }
	}
}
